<?php
    // This is used to update decorations modified thru AJAX.
    // INPUT: $_POST[]
    //
    // OUTPUT: none.
    // SIDE EFFECT: Store _POST in database after authenticating user permissions


    require_once("../../../includes.php");
    require_once("../model/resource.php");
    require_once("../model/artifact.php");
    require_once("../model/page.php");
    require_once("../model/decoration.php");

    if ( !isloggedin() ) {
        trigger_error('You mus be logged in to use this page', E_USER_ERROR);
    }

    // Orienting data
    $decoration_ident = intval( required_param('decoration_ident' ) );
    $decoration = folio_decoration::SelectWhereDecorationIdent( $decoration_ident );
    $profile_id = intval( $_SESSION['userid'] );

    // Validate permissions
    $page = folio_page::SelectWherePageIdent( $decoration->page_ident );

    if ( $page == false )
        trigger_error('Invalid page ident ', E_USER_ERROR);
    if ( !$page->Permission('update') ) {
        trigger_error('You do not have permission to edit this page', E_USER_ERROR);
    }

    // Edit data
    //$type = $_POST['type'];
    $text = $_POST['content'];

    // Update old record and requery to the screen.
    $decoration->text = $text;
    if ( folio_decoration::Update( $decoration ) ) {
        // Successfull
         echo $decoration->text;
    } else {
        // Failure
        echo 'Error: Unable to save';
    }
?>
